﻿using IM.Easy.Core.AppContext;
using IM.Easy.Core.Extensions;
using IM.Easy.Entity.Gen;
using IM.Easy.GenServices.Dtos;
using IM.Easy.GenServices.Dtos.Gen.Vue3._0;
using Mapster;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace IM.Easy.GenServices.Mapper
{
    internal class TableMapper : IRegister
    {
        public void Register(TypeAdapterConfig config)
        {

            config.ForType<DbTableInfo, DbTableDto>()
                    .Map(dest => dest.Name, src => src.Name)
                    .Map(dest => dest.Desc, src => src.Description);

            config.ForType<DbColumnInfo, GenTableColumn>()
                   .Map(dest => dest.ColumnName, src => src.DbColumnName)
                   .Map(dest => dest.Description, src => src.ColumnDescription)
                   .Map(dest => dest.IsPrimaryKey, src => src.IsPrimarykey)
                   .Map(dest => dest.PhysicalType, src => src.DataType)
                   //.Map(dest => dest.CSharpType, src => GetCSharpDatatype(src.DataType))
                   //.Map(dest => dest.CsharpField, src => src.DbColumnName.ConvertToPascal("_"))
                   .Map(dest => dest.IsRequired, src => !src.IsNullable)
                   .Map(dest => dest.IsIncrement, src => src.IsIdentity);
            //.Map(dest => dest.IsInsert, src => !src.IsIdentity || GenConstants.inputDtoNoField.Any(f => f.Contains(src.DbColumnName, StringComparison.OrdinalIgnoreCase)))
            //.Map(dest => dest.IsEdit, src => true)
            //.Map(dest => dest.IsQuery, src => false)
            //.Map(dest => dest.IsExport, src => true)
            //.Map(dest => dest.HtmlType, src => GenConstants.HTML_INPUT);


            config.ForType<GenTableColumnDto, VueColumn>()
                    .Map(dest => dest.Label, src => src.Description)
                    .Map(dest => dest.Prop, src => src.ColumnName.ToCamelCase())
                    .Map(dest => dest.Visiable, src => src.IsVisible)
                    .Map(dest => dest.DisplayType, src => src.DisplayType);

        }
    }
}
